from research.calcor import calcor_base
class SUM_byargs:
    def oncalc(self,*d,timekey=None):
        for i in d:
            if i is None:
                return None
        r=sum(d)
        return r
class SUM_byargs_byweight:
    def __init__(self,weight):
        self.weight=weight
    def oncalc(self,*d,timekey=None):
        r=0
        n=0
        for i in d:
            if i is None:
                return None
            r=r+i*self.weight[n]
            n=n+1
        return r
class SUM_bymatrix(calcor_base):
    def __init__(self,timeperiod=10):
        super().__init__(timeperiod=timeperiod,datatype="dimn")
    def calc(self):
        ss = []
        for i in self.hisdata:
            ss.append(sum(i))
        r=sum(ss)
        return r
class SUM_bymatrix_byweight(calcor_base):
    def __init__(self,weight,timeperiod=10):
        super().__init__(timeperiod=timeperiod, datatype="dimn")
        self.weight=weight
    def calc(self):
        r=0
        n=0
        for i in self.hisdata:
            r=r+sum(i)*self.weight[n]
            n=n+1
        return r
if __name__=="__main__":
    from research.calcor.calcors_graph import graph_calcor

    SUM_weight=SUM_byargs_byweight([0.5,0.3,0.2])
    print(SUM_weight.oncalc(10,5,1))
    print(SUM_weight.oncalc(10, 10, 10))